﻿/*
 * Rappelz: Endless Odyssey - The first free open source Rappelz server emulator
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rappelz.GameServer.Network;
using System.Data.Common;
using System.Data;
using Rappelz.GameServer.Network.GameClient;

namespace Rappelz.GameServer.Database
{
    /// <summary>
    /// DB_InsertGuild (smp_insert_guild)
    /// </summary>
    public class DB_InsertGuild : IDBProc
    {
        private string m_szGuildName;
        private int m_nGuildSID;
        private int m_nLeaderSID;

        public BaseObject m_CBObject = null;

        public DB_InsertGuild(string _szGuildName, int nGuildSID, int nLeaderSID)
        {
            m_szGuildName = _szGuildName;
            m_nGuildSID = nGuildSID;
            m_nLeaderSID = nLeaderSID;
        }

        public void SetCB(BaseObject obj)
        {
            m_CBObject = obj;
        }

        public void RunCB()
        {
            if (m_CBObject != null)
                m_CBObject.onEndQuery();
        }

        public bool onProcess()
        {
            DbConnection conn = GameDBManager.Instance.CreateConnection();
            DbCommand cmd = conn.CreateCommand();

            cmd.CommandText = "smp_insert_guild";
            cmd.CommandType = CommandType.StoredProcedure;

            DbParameter IN_NAME = GameDBManager.Instance.CreateInParameter(cmd, "IN_NAME", DbType.String, this.m_szGuildName);
            DbParameter IN_GUILD_SID = GameDBManager.Instance.CreateInParameter(cmd, "IN_GUILD_SID", DbType.Int32, this.m_nGuildSID);
            DbParameter IN_LEADER_SID = GameDBManager.Instance.CreateInParameter(cmd, "IN_LEADER_SID", DbType.Int32, this.m_nLeaderSID);

            conn.Open();
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Globals.Log.Error("DB_InsertGuild.onProcess Exception: {0}", ex);
            }
            conn.Close();

            return true;
        }
    }
}
